﻿#region 命名空间

// // ------------------------------------------------------------------------------
// // Copyright: © 2019- 2025  梅军章
// // 项目名称：Amm.DapperExtensions
// // 文件名称：PropertyAttribute.cs
// // 版本号: V1.0.0.0
// // 创建时间：2019-08-13 18:23
// // 更改时间：2019-08-13 18:28
// // ------------------------------------------------------------------------------

#endregion

#region 导入名称空间

using System;
using Amm.DapperExtensions.Mapper;

#endregion 导入名称空间

namespace Amm.DapperExtensions.Attributes
{
    /// <summary>
    ///     映射数据库字段
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class PropertyAttribute : Attribute
    {
        /// <summary>
        ///     数据库字段映射
        /// </summary>
        /// <param name="columnName">字段名</param>
        public PropertyAttribute(string columnName)
        {
            ColumnName = columnName;
            KeyType = KeyType.NotAKey;
            SequenceName = null;
        }

        /// <summary>
        ///     数据库字段映射
        /// </summary>
        /// <param name="ignored"></param>
        /// <param name="isReadOnly"></param>
        public PropertyAttribute(bool ignored = true, bool isReadOnly = true)
        {
            ColumnName = "ignoredName";
            Ignored = ignored;
            IsReadOnly = isReadOnly;
        }

        /// <summary>
        ///     数据库字段映射
        /// </summary>
        /// <param name="keyType"></param>
        /// <param name="columnName"></param>
        public PropertyAttribute(KeyType keyType, string columnName)
        {
            ColumnName = columnName;
            KeyType = keyType;
            SequenceName = null;
        }

        /// <summary>
        ///     数据库字段映射
        /// </summary>
        /// <param name="keyType"></param>
        /// <param name="columnName"></param>
        public PropertyAttribute(string columnName, KeyType keyType)
        {
            ColumnName = columnName;
            KeyType = keyType;
            SequenceName = null;
        }

        public string SequenceName { get; set; }
        public string ColumnName { get; set; }
        public bool Ignored { get; set; }
        public bool IsReadOnly { get; set; }
        public KeyType KeyType { get; set; }
    }
}